package members;

import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;



public class MemberCreate extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


		try {
			String Mid= req.getParameter("MID");
			String Mname= req.getParameter("MNAME");
			int Mscore= Integer.parseInt( req.getParameter("MSCORE"));			
			Class.forName("org.h2.Driver");
			Connection con = DriverManager.getConnection("jdbc:h2:~/retail","sa", "");			
			PreparedStatement ps = con.prepareStatement("INSERT INTO MEMBER VALUES(?,?,?)");
		    ps.setString(1, Mid);
		    ps.setString(2, Mname);
		    ps.setInt(3, Mscore);
		    ps.executeUpdate();
		    ps.close();
			con.close();
			resp.sendRedirect("Member/MemberMain.jsp");			
		}catch (ClassNotFoundException e) {
			e.printStackTrace();
		}catch (SQLException e) {			
			req.setAttribute("b", "SQL Exception: Insert Error!");
			req.getRequestDispatcher("Member/MemberError.jsp").forward(req, resp);							
		}catch (NumberFormatException e){
			req.setAttribute("b", "SQL Exception: Input Error!");
			req.getRequestDispatcher("Member/MemberError.jsp").forward(req, resp);		
		}
		
				
	}
}